package com.fedorvlasov.lazylist;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.nostra13.universalimageloader.core.ImageLoader;

import com.hub.R;

/**
 * 
 * @author Lubwama Samuel
 *
 */
public class LazyAdapter extends BaseAdapter {
    
    private Activity activity;
    private String[][] data;
    private static LayoutInflater inflater=null;
    public ImageLoader imageLoader; 
    public String domainOrIp="";
    
    public LazyAdapter(Activity a, String[][] imageUrls,String domain) {
    	try{
        activity = a;
        data=imageUrls;
        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        imageLoader=ImageLoader.getInstance();
        domainOrIp=domain;
    	}catch(Exception e){
    		Log.e("List Loading Error", "" + e.toString());
    	}
    }

    public int getCount() {
        return data.length;
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }
    
    public View getView(int position, View convertView, ViewGroup parent) {
        View vi=convertView;
        if(convertView==null)
         vi = inflater.inflate(R.layout.item, null);
        TextView text=(TextView)vi.findViewById(R.id.text);;
        ImageView image=(ImageView)vi.findViewById(R.id.image);
        
        text.setText("Location: ".toUpperCase()+"District:"+data[position][2]+",City:"+data[position][3]
       		 +",Town:"+data[position][4]+",Village:"+data[position][5]+"\nCost: "+data[position][9]);       
        imageLoader.displayImage(data[position][1], image);
        return vi;
    }
}